package com.ruoyi.lipin.controller;

import java.util.List;
import java.util.Arrays;
import java.util.concurrent.TimeUnit;

import lombok.RequiredArgsConstructor;
import javax.servlet.http.HttpServletResponse;
import javax.validation.constraints.*;
import cn.dev33.satoken.annotation.SaCheckPermission;
import org.springframework.web.bind.annotation.*;
import org.springframework.validation.annotation.Validated;
import com.ruoyi.common.annotation.RepeatSubmit;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.PageQuery;
import com.ruoyi.common.core.domain.R;
import com.ruoyi.common.core.validate.AddGroup;
import com.ruoyi.common.core.validate.EditGroup;
import com.ruoyi.common.core.validate.QueryGroup;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.lipin.domain.vo.LpStrategyProductVo;
import com.ruoyi.lipin.domain.bo.LpStrategyProductBo;
import com.ruoyi.lipin.service.ILpStrategyProductService;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 攻略推荐商品
 *
 * @author ruoyi
 * @date 2025-03-08
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/lipin/strategyProduct")
public class LpStrategyProductController extends BaseController {

    private final ILpStrategyProductService iLpStrategyProductService;

    /**
     * 查询攻略推荐商品列表
     */
    @SaCheckPermission("lipin:strategyProduct:list")
    @GetMapping("/list")
    public TableDataInfo<LpStrategyProductVo> list(LpStrategyProductBo bo, PageQuery pageQuery) {
        return iLpStrategyProductService.queryPageList(bo, pageQuery);
    }

    /**
     * 导出攻略推荐商品列表
     */
    @SaCheckPermission("lipin:strategyProduct:export")
    @Log(title = "攻略推荐商品", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(LpStrategyProductBo bo, HttpServletResponse response) {
        List<LpStrategyProductVo> list = iLpStrategyProductService.queryList(bo);
        ExcelUtil.exportExcel(list, "攻略推荐商品", LpStrategyProductVo.class, response);
    }

    /**
     * 获取攻略推荐商品详细信息
     *
     * @param strategyProductId 主键
     */
    @SaCheckPermission("lipin:strategyProduct:query")
    @GetMapping("/{strategyProductId}")
    public R<LpStrategyProductVo> getInfo(@NotNull(message = "主键不能为空")
                                     @PathVariable Long strategyProductId) {
        return R.ok(iLpStrategyProductService.queryById(strategyProductId));
    }

    /**
     * 新增攻略推荐商品
     */
    @SaCheckPermission("lipin:strategyProduct:add")
    @Log(title = "攻略推荐商品", businessType = BusinessType.INSERT)
    @RepeatSubmit()
    @PostMapping()
    public R<Void> add(@Validated(AddGroup.class) @RequestBody LpStrategyProductBo bo) {
        return toAjax(iLpStrategyProductService.insertByBo(bo));
    }

    /**
     * 修改攻略推荐商品
     */
    @SaCheckPermission("lipin:strategyProduct:edit")
    @Log(title = "攻略推荐商品", businessType = BusinessType.UPDATE)
    @RepeatSubmit()
    @PutMapping()
    public R<Void> edit(@Validated(EditGroup.class) @RequestBody LpStrategyProductBo bo) {
        return toAjax(iLpStrategyProductService.updateByBo(bo));
    }

    /**
     * 删除攻略推荐商品
     *
     * @param strategyProductIds 主键串
     */
    @SaCheckPermission("lipin:strategyProduct:remove")
    @Log(title = "攻略推荐商品", businessType = BusinessType.DELETE)
    @DeleteMapping("/{strategyProductIds}")
    public R<Void> remove(@NotEmpty(message = "主键不能为空")
                          @PathVariable Long[] strategyProductIds) {
        return toAjax(iLpStrategyProductService.deleteWithValidByIds(Arrays.asList(strategyProductIds), true));
    }
}
